{extend name="base"/}
{block name="css"}
<link rel="stylesheet" href="/static/backend/css/goods_order.css?t=8">
<style>
body{background: none !important;}
.thum img {width: 100px;height: 100px;}
.layui-icon.layedit-tool-face{display: none;}
</style>
{/block}
{block name="content"}
   <form id="myForm" class="layui-form" style="width:80%;" enctype="multipart/form-data">
        <div class="layui-form-item">
            <label class="layui-form-label">商品名称</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input dataIntegral" name="name" value="" lay-verify="required"  placeholder="请输入">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">所属分类</label>
            <div class="layui-input-block">
                <select name="cat_id" id="cat_id" class="con">
                    <option value="0">{:lang('请选择商品类型')}</option>
                    {volist name='selectOption' id='vo'}
                    <option value="{$vo.cat_id}">{$vo.cat_name}</option>
                    {/volist}
                </select>
            </div>
        </div>
       <div class="layui-form-item">
           <label class="layui-form-label">商品原价</label>
           <div class="layui-input-block">
               <input type="text" class="layui-input dataIntegral" name="original_price" value=""  lay-verify="required" placeholder="请输入">

           </div>
       </div>
       <div class="layui-form-item">
           <label class="layui-form-label">商品平台价</label>
           <div class="layui-input-block">
               <input type="text" class="layui-input dataIntegral" name="sale_price" value="" lay-verify=""  placeholder="请输入">

           </div>
       </div>
       <div class="layui-form-item pintuan" >
           <label class="layui-form-label">商品拼团价</label>
           <div class="layui-input-block">
               <input type="text" class="layui-input dataIntegral" name="fighting_price" value="" lay-verify=""  placeholder="请输入">

           </div>
       </div>
       <div class="layui-form-item miaosha" >
           <label class="layui-form-label">商品秒杀价</label>
           <div class="layui-input-block">
               <input type="text" class="layui-input dataIntegral" name="price_spike" value="" lay-verify=""  placeholder="请输入">

           </div>
       </div>
       <div class="layui-form-item">
           <label class="layui-form-label">库存数量</label>
           <div class="layui-input-block">
               <input type="text" class="layui-input dataIntegral" name="amount" value="" lay-verify=""  placeholder="请输入">
           </div>
       </div>
        <div class="layui-form-item">
            <label class="layui-form-label">拼团人数（拼团商品填写）</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input dataIntegral" name="people_count" value="" lay-verify=""  placeholder="拼团商品填写">
            </div>
        </div>
       <div class="layui-form-item">
           <label class="layui-form-label">地标</label>
           <div class="layui-input-block">
               <input type="text" class="layui-input dataIntegral" name="landmark" value="" lay-verify=""  placeholder="请输入">
           </div>
       </div>
       <div class="layui-form-item">
           <label class="layui-form-label">标签（用逗号隔开）</label>
           <div class="layui-input-block">
               <input type="text" class="layui-input dataIntegral" name="label" value="" lay-verify=""  placeholder="如：尾单秒杀，限时秒杀，拼团秒杀">
           </div>
       </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商品描述</label>
            <div class="layui-input-block">
                <textarea class="layui-textarea" id="LAY_demo1" style="display: none" name="detail"></textarea>
            </div>
        </div>
       <div class="layui-form-item">
           <label class="layui-form-label" >商品海报</label>
           <button type="button" class="layui-btn layui-btn-primary pull-left" style="text-align: center;line-height: 38px;border: none; background: #009688; color: #fff;" id="slide-pc1">{:lang('选择图片')}</button>
           <div class="pic-more">
               <ul class="pic-more-upload-list" id="slide-pc-priview1">
               </ul>
           </div>
       </div>
        <div class="layui-form-item" id="pics">
        <label class="layui-form-label">商品照片(图片上传大小为750)</label>
           <div class="layui-input-block" style="width: 100%;">
              <div class="layui-upload">
                 <button type="button" class="layui-btn layui-btn-primary pull-left" id="slide-pc" style="text-align: center;line-height: 38px;border: none; background: #009688; color: #fff;">{:lang('选择图片')}</button>
                 <div class="pic-more">
                    <ul class="pic-more-upload-list" id="slide-pc-priview">
                       
                    </ul>
                 </div>
              </div>
           </div>
        </div>
       <div style="margin-bottom: 50px;">
       <div class="layui-inline">
           <label class="layui-form-label">游玩开始日期</label>
           <div class="layui-input-inline">
               <input type="text" class="layui-input" id="youwan_time" name="play_start_time" placeholder="游玩开始日期">
           </div>
       </div>
       <div class="layui-inline">
           <label class="layui-form-label">游玩结束日期</label>
           <div class="layui-input-inline">
               <input type="text" class="layui-input" id="youwan_time1"  name="play_end_time" placeholder="游玩结束日期">
           </div>
       </div>
       </div>
       <div class="layui-form-item">
           <label class="layui-form-label">拼团时间限制（秒数）</label>
           <div class="layui-input-block">
               <input type="text" class="layui-input"  name="fight_time" style="width: 40%;">
           </div>
       </div>
       <div class="layui-form-item">
           <label class="layui-form-label">秒杀开始时间</label>
           <div class="layui-input-block">
           <input type="text" class="layui-input" id="time1" name="start_time" style="width: 40%;">
               </div>
       </div>
       <div class="layui-form-item">
           <label class="layui-form-label">秒杀结束时间</label>
           <div class="layui-input-block">
               <input type="text" class="layui-input" id="time2" name="end_time" style="width: 40%;">
           </div>
       </div>
        <div class="layui-form-item">
                <label class="layui-form-label">是否首页推荐</label>
                <div class="layui-input-block">
                    <select name="is_home" >
                        <option value="1">是</option>
                        <option value="0">否</option>
                        
                    </select>
                </div>
        </div>
       <div class="layui-form-item">
           <label class="layui-form-label">是否上架</label>
           <div class="layui-input-block">
               <select name="is_on" >
                   <option value="1">上架</option>
                   <option value="0">下架</option>

               </select>
           </div>
       </div>
       <div class="layui-form-item">
           <label class="layui-form-label">排序值</label>
           <div class="layui-input-block">
               <input type="text" class="layui-input dataIntegral" name="sort" value="" lay-verify=""  placeholder="请输入">
           </div>
       </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                 <input type="button"  lay-submit="" lay-filter="addAbout" value="{:lang('确认保存')}" class="" id="submit" style="width: 90px;height: 38px;text-align: center;line-height: 38px;border: none; background: #009688; color: #fff;border-radius: 2px;">
            </div>
        </div>
    </form>
{/block}
{block name="js"}
<script type="text/javascript" src="/static/backend/js/jquery.form.js"></script>
<script type="text/javascript" src="/static/backend/js/swiper.min.js"></script>
<script type="text/javascript" src="/static/backend/layui/layui.js?t=10"></script>
<script type="text/javascript" src="/static/backend/layer/layer.js?t=10"></script>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#time1' //指定元素
            ,type:'datetime'
        });
        //年月选择器
        laydate.render({
            elem: '#youwan_time'
            ,type: 'datetime'
        });
        //年月选择器
        laydate.render({
            elem: '#youwan_time1'
            ,type: 'datetime'
        });
    });
    layui.use('laydate', function(){
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#time2' //指定元素
            ,type:'datetime'
        });
    });
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        //执行一个laydate实例
        var time1 = laydate.render({
            elem: '#fromTime', //指定元素
            type: 'time',
            lang: 'en',
            value: '09:00:00'
        });
        var time2 = laydate.render({
            elem: '#toTime',
            type: 'time',
            lang: 'en',
            value: '20:00:00'

        })
    });
</script>
<script>
    layui.use('upload', function () {
        var $ = layui.jquery;
        var upload = layui.upload;
        upload.render({
            elem: '#slide-pc1',
            url: "/backend/goods/upload_img",
            size: 10000,
            type: "post",
            exts: 'jpg|png|jpeg',
            multiple: true,
            number: 9,
            before: function (obj) {
                layer.msg('图片上传中...', {
                    icon: 16,
                    shade: 0.01,
                    time: 0
                })
            },
            done: function (res) {
                console.log(res);
                layer.close(layer.msg()); //关闭上传提示窗口
                if (res.status == 0) {
                    return layer.msg(res.message);
                }
                $('#slide-pc-priview1').html(
                        '<li class="item_img" style="position: relative;"><div class="operate" style="position: absolute; width: 20px; height: 20px; left: 178px;top: 5px;"></div><img src="' +
                        res.filepath +
                        '" class="img" style="width: 200px; height: 200px;margin-left:109px;"><input type="hidden" class="shopimg" name="poster" value="' +
                        res.filepath + '" /></li>');
            }
        });
    });
    layui.use('upload', function () {
        var $ = layui.jquery;
        var upload = layui.upload;
        upload.render({
            elem: '#slide-pc',
            url: "/backend/goods/upload_img",
            size: 10000,
            type: "post",
            exts: 'jpg|png|jpeg',
            multiple: true,
            number: 9,
            before: function (obj) {
                layer.msg('图片上传中...', {
                    icon: 16,
                    shade: 0.01,
                    time: 0
                })
            },
            done: function (res) {
                console.log(res);
                layer.close(layer.msg()); //关闭上传提示窗口
                if (res.status == 0) {
                    return layer.msg(res.message);
                }
                $('#slide-pc-priview').append(
                        '<li class="item_img" style="position: relative;"><div class="operate" style="position: absolute; width: 20px; height: 20px; left: 178px;top: 5px;"><i  class="close layui-icon"></i></div><img src="' +
                        res.filepath +
                        '" class="img" style="width: 200px; height: 200px;"><input type="hidden" class="shopimg" name="pc_src[]" value="' +
                        res.filepath + '" /></li>');
            }
        });
    });
    //点击多图上传的X,删除当前的图片    
    $("body").on("click", ".close", function () {
        $(this).closest("li").remove();
    });

</script>
<script>

    $(function () {
        layui.config({
            base: "/static/admin/js/"
        }).use(['form', 'layer', 'jquery', 'layedit', 'upload'], function () {
            var form = layui.form,
                    layer = parent.layer === undefined ? layui.layer : parent.layer,
                    upload = layui.upload,
                    layedit = layui.layedit,
                    $ = layui.jquery;
            //创建一个编辑器
            var editIndex = layedit.build('LAY_demo1', {
                uploadImage: {
                    url: '/backend/goods/uploadImg/'
                    ,type: 'post'
                }
            });
            form.on("submit(addAbout)", function (data) {
                data.field.content = layedit.getContent(editIndex);

                var formdom = $('#myForm')[0]
                        ,formdata = new FormData(formdom);
                formdata.append('content', layedit.getContent(editIndex));
                $.ajax({
                    url: '/backend/goods/doadd',
                    type: 'POST',
                    data: formdata,
                    processData: false, // jQuery不要去处理发送的数据
                    contentType: false, // jQuery不要去设置Content-Type请求头
                    success: function(res) {
                        console.log(res);
                        if(res.code==1){
                            layer.msg(res.msg, {
                                time: 2000 //2秒关闭（如果不配置，默认是3秒）
                            }, function(){
                                setTimeout(parent.location.reload(),3000);
                            });
                            //刷新父页面

                        }else{
                            top.layer.msg(res.msg);
                        }
                    }

                });


                return false;
            })

        });
        $('.getimg').change(function () {
            var $imgShow = $(this).parents('.img-box').find('.show_img');
            // //console.log($imgShow)
            var reader = new FileReader();
            reader.onload = function (e) {
                $imgShow.attr("src", e.target.result)
            }
            reader.readAsDataURL(this.files[0]);
        });

    })
</script>
{/block}